package com.controller;

import com.alibaba.fastjson.JSON;
import com.entity.UserEntity;
import com.service.UserService;
import com.service.serviceImpl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.TreeSet;

@WebServlet("/app/postsUser")
public class PostsUser extends HttpServlet {
    private UserService userService = new UserServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 注释测试
        Collection<String> a = new TreeSet<String>();
        HttpSession session = req.getSession();
        String userId = session.getAttribute("userId").toString();
        UserEntity user = userService.getUser(userId);
        String userJSONString = JSON.toJSONString(user);
        resp.getWriter().write(userJSONString);
    }
}
